package yxy.game.pm2.module.matchonline;

import org.redisson.api.RList;
import yxy.apple.util.redisson.RedisException;
import yxy.cherry.game.base.redis.RedisManager;
import yxy.game.pm2.bean.Format;
import yxy.game.pm2.bean.module.BaseGameRedisLockBean;


//机器人列表
public class MatchOnlineMachine extends BaseGameRedisLockBean {

    // bean===========================================================================
    private String playerCode;// code

    private Format format;// 队伍信息

    public String getPlayerCode() {
        return playerCode;
    }

    public void setPlayerCode(String playerCode) {
        this.playerCode = playerCode;
    }

    public Format getFormat() {
        return format;
    }

    public void setFormat(Format format) {
        this.format = format;
    }

    // func===========================================================================

    // redis==========================================================================

    static public String key(int winTimes) {
        return String.format("MATCHONLINE:%s", winTimes);
    }

    static private RList<MatchOnlineMachine> touch(int winTimes) throws RedisException {
        return RedisManager.client(redis()).getList(key(winTimes));
    }

    static public RList<MatchOnlineMachine> get(int winTimes) {
        try {
            RList<MatchOnlineMachine> rlist = touch(winTimes);
            return rlist;
        } catch (RedisException e) {
            e.printStackTrace();
        }
        return null;
    }

    static public void add(int winTimes, MatchOnlineMachine moudle) {
        try {
            RList<MatchOnlineMachine> rlist = touch(winTimes);
            rlist.add(0, moudle);
            if (rlist.size() > 30) {
                rlist.trim(0, 29);
            }
        } catch (RedisException e) {
            e.printStackTrace();
        }
    }
    // lock==========================================================================


}
